<%@ page language="java" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.operations.process.ProcessTypes"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/specificationFileSetup.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">

</HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">
var lineItemCount = 0;
    function submitPage(action)
    {
        var form = document.specificationFileSetupForm;

        if(action == 'Process')
        {
            form.action.value = "Process";
        }
        form.submit();
    }

    function attachSpecFile()
    {
        var form = document.specificationFileSetupForm;
        var poFileCtrl = form.specFile;
        var pa = document.getElementById("errors");
        if ( poFileCtrl.value.trim() == "" )
        {
            pa.innerHTML = "<li>Please select a Spec file to attach</li>"
            return;
        }
        var poFileValue = poFileCtrl.value;
        poFileValue = poFileValue.replace ( '/', '\\' );
        var position = poFileValue.lastIndexOf( '\\' );
        var poFileName = poFileValue.substr(  (position+1) , poFileValue.length );

        if( poFileValue.indexOf("'") >= 0 || poFileValue.indexOf("%") >= 0 )
        {
            pa.innerHTML ='<li>'+"Spec filename should not contain ' % characters";
            return;
        }
        /*document.sortReleaseForm.poFileLocalPath.value = poFileValue.trim();*/
        form.action.value = "attachSpecFile";
        form.submit();
    }

    function confirmSpecificationFileSetup()
	{
		var form = document.specificationFileSetupForm;
        var error = document.getElementById("errors");
        error.innerHTML = "";
        if ( form.specifincationFileName.value.length == 0 )
        {

            error.innerHTML = "<li>Please Enter Specification File Name";
            return;
        }
        //else if ( form.revisionNumber.value.length == 0 )
        //{
          //  var error = document.getElementById("errors");
            //error.innerHTML = "Please Enter Revision Number";
            //return;
        //}
        //else if( !anyPartNumberSelected() )
        //{
         //   var error = document.getElementById("errors");
         //   error.innerHTML = "Please select atleast one Part Number";
         //   return;
        //}

        for ( var i=0; i < lineItemCount; i++ )
        {
            if ( form['lineItemList['+i+'].selected'].checked )
            {
                if ( form['lineItemList['+i+'].processStep_Id'].value <= 0 ) //part Number not selected
                {
                    error.innerHTML = "<li>Please select Part Number";
                    form['lineItemList['+i+'].processStep_Id'].focus();
                    return;
                }
            }
        }
        form.processName.disabled = false;
        form.action.value="confirm";
        form.submit();
        return true;

    }

    function anyPartNumberSelected()
    {
		var form = document.specificationFileSetupForm;
        var lineItemsCount = lineItemCount;
        var partNumberSelected = 'false';
        for( var i = 0; i < lineItemsCount; i++)
        {
            var partNumbersCount = form['pc'+(i+1)].value;
            for( var j = 0; j < partNumbersCount; j++)
            {
                if( form['lineItemList['+i+'].partNumberList['+j+'].selected'].checked )
                {
                    partNumberSelected = 'true';
                }
            }
        }
        if( partNumberSelected == 'true')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    function addMore()
    {
        var tab = document.getElementById ("specProductTable");
        var index = tab.rows.length;

        var newRow = tab.insertRow ( index-1 );
        var newCell = newRow.insertCell(-1);
        newCell.className = "NArialL"
        newCell.bgColor ="#DEE1E2"
        newCell.align = "middle"
        var htmltext = '<input type="checkbox" name="lineItemList['+lineItemCount+'].selected" checked="checked" class="txfield">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell(-1);
        newCell.className = "NArialL"
        newCell.bgColor ="#DEE1E2"
        newCell.align = "middle"
        htmltext = "<input type='hidden' name='lineItemList["+lineItemCount+"].partNumber' ><select name='lineItemList["+lineItemCount+"].processStep_Id' class='txfield' onchange='selectPartNumber("+lineItemCount+")'>";
        htmltext = htmltext + "<option value='-1'>Select Part Number</option>";
        <logic:iterate id="partNumber" name="partNumberList">
        htmltext = htmltext + "<option value='<bean:write property="value" name="partNumber"/>'><bean:write property="label" name="partNumber"/></option>";
        </logic:iterate>
        htmltext = htmltext + "</select>";
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell(-1);
        newCell.className = "NArialL"
        newCell.bgColor ="#DEE1E2"
        newCell.align = "middle"
        htmltext = '<input type="checkbox" name="lineItemList['+lineItemCount+'].defaultSelected"  class="txfield">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell(-1);
        newCell.className = "NArialL"
        newCell.bgColor ="#DEE1E2"
        newCell.align = "middle"
        htmltext = "<select name='lineItemList["+lineItemCount+"].vendorId' multiple='multiple' size='3' class='txfield'>";
        htmltext = htmltext + "<option value='0'>All Vendors</option>";
        <logic:iterate id="vendor" name="vendorList">
        htmltext = htmltext + "<option value='<bean:write property="value" name="vendor"/>'><bean:write property="label" name="vendor"/></option>";
        </logic:iterate>
        htmltext = htmltext + "</select>";
        newCell.innerHTML = htmltext;
        
        lineItemCount++;
    }
    function selectPartNumber( lineItemIdx )
    {
        var form = document.specificationFileSetupForm;
        var selectCtrl = form['lineItemList['+lineItemIdx+'].processStep_Id'];
        var option = selectCtrl.options[selectCtrl.selectedIndex];
        if ( option.value > 0 )
        {
            form['lineItemList['+lineItemIdx+'].partNumber'].value = option.text;
        }
        else
        {
            form['lineItemList['+lineItemIdx+'].partNumber'].value = "";
        }
    }

</SCRIPT>
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<table cellSpacing=0 cellPadding=0 width="100%" border="0">
    <tr>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/operations/releaseMenu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <td bgcolor="#ffffff"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td>
        <td bgcolor="#ffffff"><img height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td>
        <td valign="top" width="100%">
            <img height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <BR>
            <html:form name="specificationFileSetupForm" action="/specificationFileSetup" method="POST" enctype="multipart/form-data" type="com.scalar.chiptrack.operations.release.forms.SpecificationFileSetupForm" >
            <input type="hidden" name="action" value="">
            <table width='95%' align=right cellpadding='0' cellspacing='0' border='0'>
                <tr><td class="NArialW" align=center>Specification File Setup</td></tr>
                <tr><td><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></td></tr>
                <tr><td align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></td></tr>
                <tr><td><chiptrack:errors styleClass="NArialL"/></td></tr>
                <tr><td><chiptrack:info styleClass="NArialL"/></td></tr>
                 <logic:equal name="showMessage" value="TRUE">
                    <tr><td><FONT class='NArialS'color='blue'><B><%=Constants.NO_MODIFY_RIGHTS %></B></FONT></td></tr>
                </logic:equal>
                <tr><td><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></td></tr>
                <tr>
                    <td width="100%">
                        <table border="0" width="100%">
                            <tr>
                               <td class='NArialL' width='25%'>Select the Process Type :<br></td>
                                <td class="NArialL" width='75%'>
                                    <nested:select property="processName" styleClass="txfield" disabled="true" onchange="javascript:submitPage('Process');">
                                        <html:option value="">-----Select-----</html:option>
                                        <html:option value="Sort">Sort</html:option>
                                        <html:option value="Assembly">Assembly</html:option>
                                        <html:option value="Test">Test</html:option>
                                    </nested:select>
                                </td>
                            </tr>
                        </TABLE>
                    </td>
                </tr>
                <html:hidden name="specificationFileSetupForm" property="specId"></html:hidden>
                <nested:notEqual name="specificationFileSetupForm" property="processName" value="">
                <tr><td>&nbsp;</td></tr>

                <tr>
                    <td width="100%">
                      <table border="0" width="100%">
                            <tr>
                                <td width="25%" class="NArialL">Specification File Name: <b><FONT color="red">*</FONT></b></td>
                                <td width="25%" class="NArialL">
                                    <nested:text  property="specifincationFileName" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm" />
                                </td>
                                <td width="25%" class="NArialL">Revision Number:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text  property="revisionNumber" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm" />
                                </td>
                            </tr>
                            <nested:equal name="specificationFileSetupForm" property="processName" value="Test">
                            <tr>
                                <td width="25%" class="NArialL">Spec File Attachment:</td>
                                <td width="25%" class="NArialL">
                                    <html:file name="specificationFileSetupForm" property="specFile"  size="25" styleClass="txfield"/>
                                </td>
                                <td width="25%" class="NArialL"></td>
                                <td width="25%" class="NArialL"></td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL">Spec File Location:</td>
                                <td width="75%" colspan="3" class="NArialL">
                                    <a href="<%=chipTracContext%><%=ConfigManager.getSpecFilePathContext()%><nested:write name="specificationFileSetupForm" property="specPhysicalFileNameWithPathEncoded"/>" target="_newWindow" onMouseOver="window.status='Please right-click & choose Save target as';return true"onmouseout="window.status='';return true" title="Please right-click & choose Save target as"><bean:write name="specificationFileSetupForm" property="physicalFileName"/></a>
                                    <nested:hidden property="physicalFileName"/>
                                    <nested:hidden property="physicalFileNameWithPath"/>
                                </td>
                            </tr>
                            </nested:equal>

                            <nested:equal property="processName" value="Sort">
                            <tr>
                                <td width="25%" class="NArialL">Test Program Name:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text  property="testProgramName" size="25" styleClass="txfield" maxlength="100"/>
                                </td>
                                <td width="25%" class="NArialL">Test Program Revision:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text  property="testProgramRevision" size="25" styleClass="txfield" maxlength="50" />
                                </td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL">Test Flow:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text  property="testFlow" size="25" styleClass="txfield" maxlength="100" />
                                </td>
                                <td width="25%" class="NArialL"></td>
                                <td width="25%" class="NArialL"></td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL">Spec File Attachment:</td>
                                <td width="25%" class="NArialL">
                                    <html:file name="specificationFileSetupForm" property="specFile"  size="25" styleClass="txfield"/>
                                    <%--&nbsp;<a href="javascript:attachSpecFile()" onMouseOver="window.status='Click to Add a File';return true"onmouseout="window.status='';return true"><font class="bodytext"><b>Attach</b></font></a>--%>
                                </td>
                                <td width="25%" class="NArialL"></td>
                                <td width="25%" class="NArialL"></td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL">Spec File Location:</td>
                                <td width="75%" colspan="3" class="NArialL">
                                    <a href="<%=chipTracContext%><%=ConfigManager.getSpecFilePathContext()%><nested:write name="specificationFileSetupForm" property="specPhysicalFileNameWithPathEncoded"/>" target="_newWindow" onMouseOver="window.status='Please right-click & choose Save target as';return true"onmouseout="window.status='';return true" title="Please right-click & choose Save target as"><bean:write name="specificationFileSetupForm" property="physicalFileName"/></a>
                                    <nested:hidden property="physicalFileName"/>
                                    <nested:hidden property="physicalFileNameWithPath"/>
                                </td>
                            </tr>
                            </nested:equal>
                            <nested:equal property="processName" value="Assembly">
                            
							<tr>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.bomSpecFile"/>:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text   property="bom_spec" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/>
                                </td>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.bomSpecFileRevNo"/> :</td>
                                <td width="25%" class="NArialL"><nested:text   property="bom_spec_rev" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/></td>
                            </tr>
                            
							<tr>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.markingSpecFile"/>:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text   property="marking_spec" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/>
                                </td>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.markingSpecFileRevNo"/> :</td>
                                <td width="25%" class="NArialL"><nested:text   property="marking_spec_rev" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/></td>
                            </tr>

							<tr>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.buildSpecFile"/>:</td>
                                <td width="25%" class="NArialL">
                                    <nested:text   property="build_spec" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/>
                                </td>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.buildSpecFileRevNo"/> :</td>
                                <td width="25%" class="NArialL"><nested:text   property="build_spec_rev" size="25" styleClass="txfield" maxlength="50" name="specificationFileSetupForm"/></td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.diagramOne"/>:</td>
	                             <td width="25%" class="NArialL">
                                    <html:file name="specificationFileSetupForm" property="specFile"  size="25" styleClass="txfield"/>
                                </td>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.diagramTwo"/> File:</td>
                                <td width="25%" class="NArialL"><html:file name="specificationFileSetupForm" property="ceramicSpecFile"  size="25" styleClass="txfield"/></td>
							</tr>
                            <tr>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.diagramOne"/>:</td>
                                <td width="25%" class="NArialL">
                                    <a href="<%=chipTracContext%><%=ConfigManager.getSpecFilePathContext()%><nested:write name="specificationFileSetupForm" property="specPhysicalFileNameWithPathEncoded"/>" target="_newWindow" onMouseOver="window.status='Please right-click & choose Save target as';return true"onmouseout="window.status='';return true" title="Please right-click & choose Save target as"><bean:write name="specificationFileSetupForm" property="physicalFileName"/></a>
                                    <nested:hidden property="physicalFileName"/>
                                    <nested:hidden property="physicalFileNameWithPath"/>
                                </td>
                                <td width="25%" class="NArialL"><bean:message key="label.operation.release.assm.diagramTwo"/> File:</td>
                                <td width="25%" class="NArialL">
                                    <a href="<%=chipTracContext%><%=ConfigManager.getSpecFilePathContext()%><nested:write name="specificationFileSetupForm" property="ceramicSpecPhysicalFileNameEncoded"/>" target="_newWindow" onMouseOver="window.status='Please right-click & choose Save target as';return true"onmouseout="window.status='';return true" title="Please right-click & choose Save target as"><bean:write name="specificationFileSetupForm" property="physicalCeramicFileName"/></a>
                                    <nested:hidden property="physicalCeramicFileNameWithPath"/>
                                    <nested:hidden property="physicalCeramicFileName"/>
                                </td>
                            </tr>
                            </nested:equal>

                      </TABLE>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td>
                        <table border="0" align="center" width="65%" id="specProductTable">
                            <tr>
                                <td width="25%" align="center" class="NArialL" bgcolor="#993333" nowrap>
                                    <font class="NArialL"><font color="#FFFFFF">Select</font></font>
                                </td>
                                <td width="25%" align="center" class="NArialL" bgcolor="#993333" nowrap>
                                    <font class="NArialL"><font color="#FFFFFF"><nested:write name="specificationFileSetupForm" property="processName"/>&nbsp;Part&nbsp;Number</font></font>
                                </td>
                                <td width="25%" align="center" class="NArialL" bgcolor="#993333" nowrap>
                                    <font class="NArialL"><font color="#FFFFFF">Default</font></font>
                                </td>
                                <td width="25%" align="center" class="NArialL" bgcolor="#993333" nowrap>
                                    <font class="NArialL"><font color="#FFFFFF">Vendor</font></font>
                                </td>
                            </tr>
                            <%
                                int lineItemCount = 0;
                            %>
                            <nested:iterate id="partNumber"  name="specificationFileSetupForm" property="lineItemList" type="com.scalar.chiptrack.operations.release.SpecificationFileSetupPartNumber">
                            <%
                                lineItemCount++;
                            %>
                            <tr>

                                <td width="35%" class="NArialL" bgcolor="#DEE1E2" align="middle"><nested:checkbox property="selected" styleClass="txfield"/></td>
                                <td width="35%" class="NArialL" bgcolor="#DEE1E2" align="left">
                                    <nested:hidden property="partNumber"/>
                                    <nested:greaterThan value="0" property="processStep_Id">
                                        <nested:write property="partNumber"/>
                                        <nested:hidden property="processStep_Id"/>
                                    </nested:greaterThan>
                                    <nested:lessEqual value="0" property="processStep_Id">
                                        <%
                                            String onchange="selectPartNumber("+ (lineItemCount-1) + ");";
                                        %>
                                        <nested:select property="processStep_Id" styleClass="txfield" onchange="<%=onchange%>">
                                            <html:option value="-1">Select Part Number</html:option>
                                            <html:options collection="partNumberList" labelProperty="label" property="value"/>
                                        </nested:select>
                                    </nested:lessEqual>
                                </td>
                                <td width="30%" class="NArialL" bgcolor="#DEE1E2" align="middle">
                                    <nested:checkbox property="defaultSelected" styleClass="txfield"/>
                                </td>
                                <td width="30%" class="NArialL" bgcolor="#DEE1E2" align="middle">
                                    <nested:select property="vendorId" styleClass="txfield" multiple="true" size="3">
                                        <html:option value="0">All Vendors</html:option>
                                        <html:options collection="vendorList" labelProperty="label" property="value"/>
                                    </nested:select>
                                </td>
                            </tr>
                            </nested:iterate>
                            <script type="text/javascript">
                                lineItemCount = <%=lineItemCount%>;
                            </script>
                            <tr>
                                <td class='NArialL' colspan="4" align="right" style="color:red">
                                    <a href="javascript:addMore()"><img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border=0 onmouseover="window.status='Click here to add More';return true" onmouseout="window.status='';return true" title=""></a>
                                </td>
                            </tr>
                        </TABLE>
                    </td>
                </tr>
                    <tr>
                        <td width="100%">
                            <table align="center" width="65%">
                                <td width="100%" align=center>
                                    <chiptrack:restrictedLink functionality='<%=Functionality.SPECIFICATION_FILE_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:confirmSpecificationFileSetup();' onmouseover="window.status='Click to Save Specification File Setup';return true" onmouseout="window.status='';return true">
                                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" ALIGN="BOTTOM" BORDER="0"  width="53" height="17" title="Click here to Save Specification File Setup"/>
                                    </chiptrack:restrictedLink>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="<%=chipTracContext%>/specificationFileSetup.do" onmouseover="window.status='Click to Cancel';return true" onmouseout="window.status='';return true"  title="Click here to Cancel"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"></a>
                                </td>
                            </TABLE>
                        </td>
                    </tr>

                </nested:notEqual>
                <tr><td>&nbsp;</td></tr>
                <tr height="30"><td colspan="4">&nbsp;</td></tr>
            </table>
            </html:form>
            <!-- till here -->
            <BR><BR><BR>
        </td>
        <td bgcolor="#ffffff"><img height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></td>
    </tr>
</table>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>
